<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<script language="javascript" type="text/javascript">
<!--
    var currPageViewIndex = 0;
    var pageViewCount = 0;
    var page = <%=ViewData["page"] %>;
    var recordCount = <%=ViewData["recordCount"] %>;
    var pageSize = <%=ViewData["pageSize"] %>;
    var pageCount = recordCount%pageSize==0?recordCount/pageSize:Math.floor(recordCount/pageSize)+1;
    pageViewCount = pageCount%10==0?pageCount/10:Math.floor(pageCount/10)+1;
    
    $(document).ready(function(result) {        
        if(recordCount == 0) {
            $$('pageControlsDiv').style.display = 'none';
            return;
        }       
        var innerHtml = '';
        for(var i=1; i<=pageViewCount; i++){
            if( ((i-1)*10 <= page) && (page < (i*10)) ){
                innerHtml+='<div id="pageView'+i+'">';
                currPageViewIndex = i;
            }else {
                innerHtml+='<div id="pageView'+i+'" style="display:none">';
            }
            for(var j=0; j<10; j++){
                var pageIndex = (i-1)*10 + j;
                if(pageIndex > (pageCount-1)) break;
                if(pageIndex == page)
                    innerHtml += "<strong>"+(pageIndex + 1)+"</strong>";
                else 
                    innerHtml += '<a href="javascript:JunpToPage('+pageIndex+');">' + (pageIndex + 1) + '</a>';
            }
            innerHtml+='</div>';
        }        
        $$('pageControls').innerHTML = innerHtml;
    });
    
    function firstPageView(){
        $$('pageView' + currPageViewIndex).style.display = 'none';
        $$('pageView' + 1).style.display = '';
        currPageViewIndex = 1;
    }
    
    function prevPageView(){
        if(currPageViewIndex == 1) return;
        $$('pageView' + currPageViewIndex).style.display = 'none';
        $$('pageView' + (--currPageViewIndex)).style.display = '';
        
    }
   
    function nextPageView(){
        if(currPageViewIndex == pageViewCount) return;
        $$('pageView' + currPageViewIndex).style.display = 'none';
        $$('pageView' + (++currPageViewIndex)).style.display = '';
    }
    
    function lastPageView(){
        $$('pageView' + currPageViewIndex).style.display = 'none';
        $$('pageView' + pageViewCount).style.display = '';
        currPageViewIndex = pageViewCount;
    }
    
    function GoCustomPage(){
        var goPage = $("#customPageInput").val();
        //var pageNo = parseInt(goPage);
        JunpToPage(goPage);
        //alert(goPage);
    }
//-->
</script>
